const register = require('babel-core/register')
register(require('../babel/babel.runtime'))
const Koa = require('koa')
const webpack = require('webpack')
const proxy = require('koa-proxies')
// 中间件容器，把webpack处理后的文件传递给一个服务器
const wdm = require('./middleware/devMiddleware').default
// 在内存中编译的插件，不写入磁盘来提高性能
const whm = require('./middleware/hotMiddleware').default

const { devConfig } = require('../webpack/webpack-client')

const compiler = webpack(devConfig)
const app = new Koa()

// app.use(compress())

app.use(wdm(compiler, {
    publicPath: devConfig.output.publicPath,
    quiet: true,
    stats: { colors: true },
    watchOptions: devConfig.watchOptions
}))

app.use(whm(compiler))

app.use(proxy("/**", {
    target: `http://localhost:3001`,
    changeOrigin: true,
    logs: true
}))

app.listen(3000, (err) => {
    if (err) {
        console.error(`==> 😭  OMG!!! ${err}`)
    }
    console.info(`==> 🌎  Listening at http://localhost:3000`)

})

